window.onload = function(){
    $('#searchText').click(function () {
        $("#searchBar").addClass("weui-search-bar_focusing");
        $('#searchInput').focus()
    })
    $('#searchCancel').click(function () {
        $("#searchBar").removeClass("weui-search-bar_focusing");
    })
    $('#searchInput').blur(function () {
        $("#searchBar").removeClass("weui-search-bar_focusing");
    })
    $.ajax({
        type: "POST",
        url: 'http://hplqytest.suoluomei.cn/index.php?s=/Hr/Index/getSearchSave',
        data: {
            api_key: '195a9b99ea7a0d259151b5c412bb631b'
        },
        dataType: "json",
        success: function (data) {
            console.log(data)
            if(data.errcode === 0) {
                for (let i = 0; i < data.data.result.length; i++) {
                // <a href="+'./appraise.html?id='+ data.data.result[i].userid +">\n" +
                    let myli = "<li class=\"weuiLi\">\n" +
                        "            <a href=\"./appraise.html\">\n" +
                        "              <div class=\"weuiListBox\">\n" +
                        "                <div class=\"weuiListL\">\n" +
                        "                  <div class=\"conMonth\">"+ data.data.result[i].month +"月</div>\n" +
                        "                  <div class=\"conDay\">"+ data.data.result[i].day +"</div>\n" +
                        "                </div>\n" +
                        "                <div class=\"weuiList\">\n" +
                        "                  <div class=\"conT\">\n" +
                        "                    <div class=\"conTitle\">"+ data.data.result[i].name +"</div>\n" +
                        "                    <div class=\"conVacancy\">"+ data.data.result[i].mobile +"</div>\n" +
                        "                  </div>\n" +
                        "                  <div class=\"conT\">\n" +
                        "                    <div class=\"conZhiwei\">应聘职位："+ data.data.result[i].name_job +"</div>\n" +
                        "                    <div class=\"conVacancy\" style=\"color: green;\">"+ data.data.result[i].name_status +"</div>\n" +
                        "                  </div>\n" +
                        "                </div>\n" +
                        "              </div>\n" +
                        "            </a>\n" +
                        "          </li>";
                    $('.weuiUl').append(myli);
                }
                // $('.conColor').each(function () {
                //     for (let i = 0; i < data.data.result.length; i++) {
                //         if (data.data.result[i].name_status == '面试不通过') {
                //             $(this).css('color','#999999')
                //         }
                //     }
                // })
            } else{
                let myli = "<div class='zanwu' style=\"padding: 50px 10px;box-sizing: border-box;text-align: center;margin: 0 auto;width: 100%;color: #999999\">暂无数据</div>";
                $('.weuiUl').append(myli);
            }
        },
        error: function () {
            let myli = "<div class='zanwu' style=\"padding: 50px 10px;box-sizing: border-box;text-align: center;margin: 0 auto;width: 100%;color: #999999\">暂无数据</div>";
            $('.weuiUl').append(myli);
        }
    })
    $('#searchInput').on('input propertychange', function() {
        let value = $("#searchInput").val()
        $.ajax({
            type: "POST",
            url: 'http://hplqytest.suoluomei.cn/index.php?s=/Hr/Index/getNameSearchSave',
            data: {
                api_key: '195a9b99ea7a0d259151b5c412bb631b',
                name: value
            },
            dataType: "json",
            success: function (data) {
                console.log(data)
                if(data.errcode === 0) {
                    $('.weuiLi').remove()
                    $('.zanwu').remove()
                    for (let i = 0; i < data.data.result.length; i++) {
                        let myli = "<li class=\"weuiLi\">\n" +
                            "            <a href=\"./appraise.html\">\n" +
                            "              <div class=\"weuiListBox\">\n" +
                            "                <div class=\"weuiListL\">\n" +
                            "                  <div class=\"conMonth\">"+ data.data.result[i].month +"月</div>\n" +
                            "                  <div class=\"conDay\">"+ data.data.result[i].day +"</div>\n" +
                            "                </div>\n" +
                            "                <div class=\"weuiList\">\n" +
                            "                  <div class=\"conT\">\n" +
                            "                    <div class=\"conTitle\">"+ data.data.result[i].name +"</div>\n" +
                            "                    <div class=\"conVacancy\">"+ data.data.result[i].mobile +"</div>\n" +
                            "                  </div>\n" +
                            "                  <div class=\"conT\">\n" +
                            "                    <div class=\"conZhiwei\">应聘职位："+ data.data.result[i].name_job +"</div>\n" +
                            "                    <div class=\"conVacancy\" style=\"color: green;\">"+ data.data.result[i].name_status +"</div>\n" +
                            "                  </div>\n" +
                            "                </div>\n" +
                            "              </div>\n" +
                            "            </a>\n" +
                            "          </li>";
                        $('.weuiUl').append(myli);
                    }
                }else {
                    $('.weuiLi').remove()
                    $('.zanwu').remove()
                    let myli = "<div class='zanwu' style=\"padding: 50px 10px;box-sizing: border-box;text-align: center;margin: 0 auto;width: 100%;color: #999999\">暂无数据</div>";
                    $('.weuiUl').append(myli);
                }
            },
            error: function () {
                $('.weuiLi').remove()
                $('.zanwu').remove()
                let myli = "<div class='zanwu' style=\"padding: 50px 10px;box-sizing: border-box;text-align: center;margin: 0 auto;width: 100%;color: #999999\">暂无数据</div>";
                $('.weuiUl').append(myli);
            }
        })
    })
}
